//
//  MingXiViewController.m
//  Cxzc
//
//  Created by hwd on 17/8/7.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "MingXiViewController.h"
#import "MingXiCell.h"
static NSString *const MingXiCellID = @"MingXiCellID";
@interface MingXiViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableV;
@property (nonatomic,strong)UISegmentedControl * selectButton;//Segment 选择按钮
@property (nonatomic,strong)NSMutableArray *dataArr;
@property (nonatomic,assign)NSInteger pageNumber;//页码
@property (nonatomic,assign)NSInteger chooseSeg;//0 消费记录 1 充值记录
@end

@implementation MingXiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _pageNumber = 1;
    _chooseSeg = 0;
    self.navigationItem.titleView = [self segmentControlWithItems:@[@"充值明细", @"消费明细"]];
    [self.view addSubview:self.tableV];
    [self addgetRequest:NO];
}
-(NSMutableArray *)dataArr{//数组初始化
    if (!_dataArr) {
        _dataArr = [NSMutableArray new];
    }
    return _dataArr;
}
//UISegmentedControl 点击事件
- (void)segmentControlClicked:(UISegmentedControl *)segmentControl {
    _chooseSeg = segmentControl.selectedSegmentIndex;
    _pageNumber = 1;
    [_dataArr removeAllObjects];
    [self addgetRequest:YES];
}
-(void)addgetRequest:(BOOL)isShuaXin{//列表数据请求
    
//    if (self.dataArr.count<=0) {//数据为空 加载动画
//        [HudHelper showProgressHudWithMessage:@"" toView:self.view];
//    }
    //_chooseSeg ＝ 0 消费记录 1 充值记录
//    dispatch_async(dispatch_get_global_queue(0, 0), ^{
//        [HttpRequest PostrequestUrl:_chooseSeg==0?@"/fluentDrive/interface/user/getCxUserConsumeRecord":@"/fluentDrive/interface/user/getCxUserRechargeInfo" Dic:@{_chooseSeg==0?@"cxUser.id":@"userId":[Storage getToken],@"pageNo":[NSString stringWithFormat:@"%ld",_pageNumber],@"pageSize":@"15"} completion:^(NSDictionary *responseDic)
//         {
//             dispatch_async(dispatch_get_main_queue(), ^{
//                 //请求成功
//                 if ([responseDic[@"success"] boolValue] && [responseDic[@"pageNo"] integerValue] == _pageNumber  ) {
//                     if (isShuaXin) {//刷新清除数据
//                         [_dataArr removeAllObjects];
//                     }
//                     NSArray *arr = [[NSArray alloc]initWithArray:responseDic[@"data"]];
//                     for (int i = 0; i<arr.count ; i++) {
//                         [self.dataArr addObject:arr[i]];
//                     }
//                     if (_dataArr.count<=0) {//数据为空提示
//                         [TomamaUI creatAlertWithTarget:self message:@"没有搜索到内容" timeInterval:2];
//                     }
//                 }
//                 [HudHelper hideHudToView:self.view];
//                 [_tableV reloadData];
//                 [_tableV.mj_header endRefreshing];
//                 [_tableV.mj_footer endRefreshing];
//             });
//         }];
//    });
}
-(UITableView *)tableV//创建tableView
{
    if (!_tableV) {//不存在 创建
        _tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREENW, SCREENH-64) style:UITableViewStyleGrouped];
        _tableV.rowHeight = 85*screenW_6;
        _tableV.backgroundColor = backColor;
        _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableV.showsVerticalScrollIndicator = NO;
        _tableV.delegate = self;
        _tableV.dataSource = self;
        [_tableV registerClass:[MingXiCell class] forCellReuseIdentifier:MingXiCellID];
        //刷新
        _tableV.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
            _pageNumber = 1;
            [self addgetRequest:YES];
        }];
        //加载
        _tableV.mj_footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
            _pageNumber++;
            [self addgetRequest:NO];
        }];
    }
    return _tableV;
}
#pragma Mark TableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.00001;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MingXiCell *cell = [tableView dequeueReusableCellWithIdentifier:MingXiCellID forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    if (_dataArr.count>0) {//数据不为空 加载Cell
        [cell LoadDataDic:nil WithType:_chooseSeg];
//    }
    return cell;
}
@end
